import 'package:fish_redux/fish_redux.dart';
import 'package:kunlun_gas/PublicSource/utils/common_utils.dart';
import 'package:kunlun_gas/PublicSource/widgets/photo_album_widget.dart';

import 'action.dart';
import 'state.dart';

Effect<InstallHistoryDetailViewState> buildEffect() {
  return combineEffects(<Object, Effect<InstallHistoryDetailViewState>>{
    InstallHistoryDetailViewAction.onTapResultPic: _onTapResultPic,
    Lifecycle.initState: _initState,
  });
}

void _onAction(Action action, Context<InstallHistoryDetailViewState> ctx) {
}

void _initState(Action action, Context<InstallHistoryDetailViewState> ctx) {

}

void _onTapResultPic(Action action, Context<InstallHistoryDetailViewState> ctx) async {
  var file = action.payload['file'];
  var list = action.payload['list'];
  List<GalleryExampleItem> items = list.map<GalleryExampleItem>((e) {
    int index = list.indexOf(e);
    return GalleryExampleItem(
      id: '$index',
      resource: e,
    );
  }).toList();
  items = await CommonUtils.showPhotoAlbumView(
    ctx.context,
    initialIndex: list.indexOf(file),
    galleryItems: items,
  );
}